package mtt.view;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import mtt.control.DisplayController;

/**
 * @author hyphen
 */
public class MainMenuView implements IMttDisplayAble {

	private static final Command commandExit = new Command("Beenden",
			Command.EXIT, 0);;

	private static final Command commandSelect = new Command("Anzeigen",
			Command.ITEM, 0);

	public static final int index_SHOW_CALLENDAR = 0;

	public static final int index_SHOW_INFO = 3;

	public static final int index_SHOW_MARKS = 1;
	public static final int index_SHOW_OPTIONS = 2;
	private static final MainMenuView mainMenuView = new MainMenuView();

	/**
	 * MainMenuView Factory, liefert immer die gleiche Instanz
	 * 
	 * @return
	 */
	public static final MainMenuView getInstance() {
		return mainMenuView;
	}

	/**
	 * liefert den String zum index
	 * 
	 * @return String value of index or null
	 */
	public static String getStringOfOption(int index) {
		switch (index) {
		case index_SHOW_CALLENDAR:
			return "Kalender";
		case index_SHOW_MARKS:
			return "Noten";
		case index_SHOW_OPTIONS:
			return "Optionen";
		case index_SHOW_INFO:
			return "Info";

		default:
			return null;
			;
		}
	}

	private final List listMenu = new List("MTT-Hauptmenü", List.IMPLICIT);

	/**
	 * Privater Konstruktor, use MainMenuView.getInstance()
	 */
	private MainMenuView() {

		/*
		 * Menüpunkte einfügen
		 */
		listMenu.insert(index_SHOW_CALLENDAR,
				getStringOfOption(index_SHOW_CALLENDAR), null);
		listMenu.insert(index_SHOW_MARKS, getStringOfOption(index_SHOW_MARKS),
				null);
		listMenu.insert(index_SHOW_OPTIONS,
				getStringOfOption(index_SHOW_OPTIONS), null);
		listMenu.insert(index_SHOW_INFO, getStringOfOption(index_SHOW_INFO),
				null);

		listMenu.addCommand(commandSelect);
		listMenu.addCommand(commandExit);

		listMenu.setCommandListener(DisplayController.getInstance());
	}

	public void commandAction(Command command) {
		if (command == MainMenuView.commandSelect) {
			int selectedIndex = listMenu.getSelectedIndex();

			DisplayController displayController = DisplayController
					.getInstance();

			switch (selectedIndex) {
			case index_SHOW_CALLENDAR:
				displayController.showWeekViewCurrent();
				break;
			case index_SHOW_MARKS:
				displayController.showMarkView();
				break;
			case index_SHOW_OPTIONS:
				displayController.showOptionView();
				break;
			case index_SHOW_INFO:
				displayController.showInfoView();
				break;
			default:
				displayController.showMainMenu();
				break;
			}
		}
	}

	public Displayable getDisplayable() {
		return this.listMenu;
	}

}
